<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </div>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px;">条码名称</span>
                <el-input v-model="tableParam.barCodeName" style="width: 240px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">条码编码</span>
                <el-input v-model="tableParam.code" style="width: 240px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">业务名称</span>
                <el-input v-model="tableParam.businessName" style="width: 240px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <div class="card_nav">
            <div>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TIANJIA'))!==-1" size="small" class="bottom_all" style="margin-left: 0;" @click="chongZhi(),addFromDate('添加'),multipleType=true">
                <i class="icon iconfont iconicon_button_add" style="font-size: 12px;"></i>
                添加
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='SHANCHU'))!==-1" size="small" class="bottom_two" @click="Delete">
                <i class="icon iconfont iconicon_button_delete" style="font-size: 12px;"></i>
                删除
              </el-button>
              <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TMLXBMWH'))!==-1" size="small" class="bottom_all_two" style="margin-left: 12px" @click="codingTypegetCodingTypeFun()">条码类型编码维护</el-button>
            </div>
            <div>
              <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px;">
                <el-link :underline="false">
                  <span class="el-icon--left">
                    <i class="iconfont iconicon_button_filtrate"></i>
                  </span>
                  筛选
                </el-link>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="(item, index) in table" :key="index">
                    <el-checkbox v-model="item.status">{{ item.label }}</el-checkbox>
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
              <el-link v-if="ButtonList.findIndex(res=>(res.buttonValue=='DAOCHU'))!==-1" :underline="false" @click="load()">
                <span class="el-icon--left">
                  <i class="iconfont iconicon_button_export1"></i>
                </span>
                导出
              </el-link>
            </div>
          </div>
          <div v-loading="tableLoading" class="card_info" :style="style">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
              <el-table-column align="center" type="selection"></el-table-column>
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label =='操作'?'right':false">
                  <template slot-scope="scope">
                    <el-button v-if="item.label == '操作'&&ButtonList.findIndex(res=>(res.buttonValue=='XIUGAI'))!==-1" class=" bottom_one" size="mini" @click="updateFromDate(scope.row, '修改'),show1Fun(scope.row),multipleType=false">
                      <i class="icon iconfont iconicon_button_modification" style="font-size: 12px;"></i>
                      修改
                    </el-button>
                    <span v-if="item.label !== '操作'">{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="980px" :close-on-click-modal="false" :before-close="resetFromDate">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate" :key="fromDate.fromid" :rules="rules" :inline="true" :model="fromDate" label-width="110px">
          <el-form-item prop="code">
            <span slot="label" style="color:  #FF0000 ;">条码编码</span>
            <el-input v-model="fromDate.code" placeholder="请输入" clearable @input="changecode('code')" @blur="codeFun"></el-input>
          </el-form-item>
          <el-form-item label="业务类型">
            <el-radio-group v-model="fromDate.type" @change="businessIdListFun(fromDate.type)">
              <el-radio :label="1">公司业务</el-radio>
              <el-radio :label="2">站点业务</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item prop="companyId">
            <span slot="label" style="color:  #FF0000 ;">公司</span>
            <el-select v-model="fromDate.companyId" filterable placeholder="请选择" @change="setstationIdlist(fromDate.companyId)">
              <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-if="fromDate.type==2" prop="stationId">
            <span slot="label" style="color: #FF0000 ;">站点名称</span>
            <el-select :key="fromDate.stationId" v-model="fromDate.stationId" placeholder="请选择" :disabled="fromDate.companyId==''">
              <el-option v-for="item in stationlist" :key="item.stationId" :label="item.stationName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="businessId" :rules="[{required: true,message: '请选择业务',trigger: 'blur',},]">
            <span slot="label" style="color:  #FF0000 ;">绑定业务</span>
            <el-select :key="999" ref="businessId" v-model="fromDate.businessId" filterable :multiple="multipleType" placeholder="请选择" @change="$forceUpdate()">
              <el-option v-for="(item,k) in businessIdList" :key="k" :label="item.label" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="barCodeName">
            <span slot="label" style="color:  #FF0000 ;">条码名称</span>
            <el-input v-model="fromDate.barCodeName" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item prop="barCodeTypeId">
            <span slot="label" style="color:  #FF0000 ;">条码类型</span>
            <el-select v-model="fromDate.barCodeTypeId" placeholder="请选择">
              <el-option v-for="item in barCodeTypeIdlist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <div>
            <el-form-item>
              <span slot="label">示例</span>
              <img class="logo" src="@/assets/barcode.png" />
            </el-form-item>
          </div>
          <div>
            <el-form ref="refruleOne" :rules="ruleOnerules" :inline="true" :model="ruleOne" label-width="110px">
              <el-form-item prop="typeId">
                <span slot="label" style="color:  #FF0000 ;">条码规则1</span>
                <el-select v-model="ruleOne.typeId" placeholder="请选择">
                  <el-option v-for="(item, index) in ruleList" :key="index" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleOne.typeId == 1" prop="Name">
                <span slot="label" style="color:  #808080 ;">固定值</span>
                <el-input v-model="ruleOne.Name" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleOne.typeId == 2" prop="Name">
                <span slot="label" style="color:  #808080 ;">函数</span>
                <el-select v-model="ruleOne.Name" placeholder="请选择">
                  <el-option v-for="(item,k) in NameList" :key="k" :label="item.lable" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleOne.typeId == 3" prop="value">
                <span slot="label" style="color:#808080;">自增位数</span>
                <el-input v-model="ruleOne.value[0]" type="Number" placeholder="最大值8" oninput="if(value > 8)value = 8"></el-input>
              </el-form-item>
              <el-form-item v-if="ruleOne.typeId == 3" prop="value" label-width="160px">
                <span slot="label" style="color:#808080">自增规则（每次加）</span>
                <el-input v-model="ruleOne.value[1]" style="width:270px" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleOne.typeId == 3" prop="value">
                <span slot="label" style="color:#808080;">应用起始值</span>
                <el-input v-model="ruleOne.value[2]" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div>
            <el-form ref="refruleOneA" :rules="ruleOnerules" :inline="true" :model="ruleTwo" label-width="110px">
              <el-form-item>
                <span slot="label">条码规则2</span>
                <el-select v-model="ruleTwo.typeId" placeholder="请选择">
                  <el-option v-for="(item, index) in ruleList" :key="index" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleTwo.typeId == 1" prop="Name">
                <span slot="label" style="color:  #808080 ;">固定值</span>
                <el-input v-model="ruleTwo.Name" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleTwo.typeId == 2" prop="Name">
                <span slot="label" style="color:  #808080 ;">函数</span>
                <el-select v-model="ruleTwo.Name" placeholder="请选择">
                  <el-option v-for="(item,k) in NameList" :key="k" :label="item.lable" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleTwo.typeId == 3">
                <span slot="label" style="color:#808080;">自增位数</span>
                <el-input v-model="ruleTwo.value[0]" type="Number" placeholder="最大值8" oninput="if(value > 8)value = 8"></el-input>
              </el-form-item>
              <el-form-item v-if="ruleTwo.typeId == 3" label-width="160px">
                <span slot="label" style="color:#808080;">自增规则（每次加）</span>
                <el-input v-model="ruleTwo.value[1]" style="width: 270px;" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleTwo.typeId == 3">
                <span slot="label" style="color:#808080;">应用起始值</span>
                <el-input v-model="ruleTwo.value[2]" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div>
            <el-form ref="refruleOneB" :rules="ruleOnerules" :inline="true" :model="ruleThree" label-width="110px">
              <el-form-item>
                <span slot="label">条码规则3</span>
                <el-select v-model="ruleThree.typeId" placeholder="请选择">
                  <el-option v-for="(item, index) in ruleList" :key="index" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleThree.typeId == 1" prop="Name">
                <span slot="label" style="color:  #808080 ;">固定值</span>
                <el-input v-model="ruleThree.Name" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleThree.typeId == 2" prop="Name">
                <span slot="label" style="color:  #808080 ;">函数</span>
                <el-select v-model="ruleThree.Name" placeholder="请选择">
                  <el-option v-for="(item,k) in NameList" :key="k" :label="item.lable" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleThree.typeId == 3">
                <span slot="label" style="color:#808080;">自增位数</span>
                <el-input v-model="ruleThree.value[0]" type="Number" placeholder="最大值8" oninput="if(value > 8)value = 8"></el-input>
              </el-form-item>
              <el-form-item v-if="ruleThree.typeId == 3" label-width="160px">
                <span slot="label" style="color:#808080;">自增规则（每次加）</span>
                <el-input v-model="ruleThree.value[1]" style="width: 270px;" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleThree.typeId == 3">
                <span slot="label" style="color:#808080;">应用起始值</span>
                <el-input v-model="ruleThree.value[2]" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div>
            <el-form ref="refruleOneC" :rules="ruleOnerules" :inline="true" :model="ruleFour" label-width="110px">
              <el-form-item>
                <span slot="label">条码规则4</span>
                <el-select v-model="ruleFour.typeId" placeholder="请选择">
                  <el-option v-for="(item, index) in ruleList" :key="index" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleFour.typeId == 1" prop="Name">
                <span slot="label" style="color:  #808080 ;">固定值</span>
                <el-input v-model="ruleFour.Name" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleFour.typeId == 2" prop="Name">
                <span slot="label" style="color:  #808080 ;">函数</span>
                <el-select v-model="ruleFour.Name" placeholder="请选择">
                  <el-option v-for="(item,k) in NameList" :key="k" :label="item.lable" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleFour.typeId == 3">
                <span slot="label" style="color:#808080;">自增位数</span>
                <el-input v-model="ruleFour.value[0]" type="Number" placeholder="最大值8" oninput="if(value > 8)value = 8"></el-input>
              </el-form-item>
              <el-form-item v-if="ruleFour.typeId == 3" label-width="160px">
                <span slot="label" style="color:#808080;">自增规则（每次加）</span>
                <el-input v-model="ruleFour.value[1]" style="width: 270px;" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleFour.typeId == 3">
                <span slot="label" style="color:#808080;">应用起始值</span>
                <el-input v-model="ruleFour.value[2]" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div v-if="fromDate.type == 2">
            <el-form ref="refruleOneD" :rules="ruleOnerules" :inline="true" :model="ruleFive" label-width="110px">
              <el-form-item>
                <span slot="label">条码规则5</span>
                <el-select v-model="ruleFive.typeId" placeholder="请选择">
                  <el-option v-for="(item, index) in ruleList" :key="index" :label="item.itemName" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleFive.typeId == 1" prop="Name">
                <span slot="label" style="color:  #808080 ;">固定值</span>
                <el-input v-model="ruleFive.Name" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleFive.typeId == 2" prop="Name">
                <span slot="label" style="color:  #808080 ;">函数</span>
                <el-select v-model="ruleFive.Name" placeholder="请选择">
                  <el-option v-for="(item,k) in NameList" :key="k" :label="item.lable" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item v-if="ruleFive.typeId == 3">
                <span slot="label" style="color:#808080;">自增位数</span>
                <el-input v-model="ruleFive.value[0]" type="Number" placeholder="最大值8" oninput="if(value > 8)value = 8"></el-input>
              </el-form-item>
              <el-form-item v-if="ruleFive.typeId == 3" label-width="160px">
                <span slot="label" style="color:#808080;">自增规则（每次加）</span>
                <el-input v-model="ruleFive.value[1]" style="width: 270px;" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
              <el-form-item v-if="ruleFive.typeId == 3">
                <span slot="label" style="color:#808080;">应用起始值</span>
                <el-input v-model="ruleFive.value[2]" type="Number" placeholder="请输入" clearable></el-input>
              </el-form-item>
            </el-form>
          </div>
          <el-form-item>
            <span slot="label">备注</span>
            <el-input v-model="fromDate.remark" style="width: 760px;" type="textarea" :rows="5" resize="none" placeholder="请输入" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="resetFromDate">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" :loading="loading" @click="submit()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 条码类型编码维护 -->
    <el-dialog v-dialogDrag :visible.sync="look1Type1" width="900px">
      <span slot="title" class="dialog-title">条码类型编码维护</span>
      <div class="dialoginfo">
        <div>
          <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="arrList" tooltip-effect="dark">
            <el-table-column label="条码类型" align="center" prop="codingType"></el-table-column>
            <el-table-column label="编码" align="center">
              <template slot-scope="scope">
                <el-input-number v-model="scope.row.codingValue" :precision="0" style="width: 100%;" :controls="false"></el-input-number>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="look1Type1 =false ">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" @click="codingTypesaveCodingTypeFun()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage,
  batchUpdateOrDelete,
  updateSortNum,
  saveOrUpdate,
  Download,
  qureyCodeIs,
  getStationByCompanyId,
  codingTypegetCodingType,
  codingTypesaveCodingType
} from "@/api/basicConfig/barcode.js";
import { getDicType } from "@/api/common.js";
import { permissionsCompanyList } from "@/api/common.js";
import { setTimeout } from 'timers';
export default {
  mixins: [mixin],
  data() {
    return {
      arrList: [],
      look1Type1: false,
      loading: false,
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      batchUpdateOrDelete: batchUpdateOrDelete,
      updateSortNum: updateSortNum,
      saveOrUpdate: saveOrUpdate,
      DownloadURL: Download,
      /*表格数据*/
      table: [
        {
          label: "条码编码",
          width: "120",
          prop: "code",
          status: true,
        },
        {
          label: "站点",
          width: "140",
          prop: "stationName",
          status: true,
        },
        {
          label: "绑定业务",
          width: "140",
          prop: "businessName",
          status: true,
        },
        {
          label: "条码名称",
          width: "160",
          prop: "barCodeName",
          status: true,
        },
        {
          label: "条码类型",
          width: "140",
          prop: "barCodeTypeName",
          status: true,
        },
        {
          label: "条码规则",
          width: "320",
          prop: "codeRule",
          status: true,
        },
        {
          label: "当前编码值",
          width: "320",
          prop: "currentValue",
          status: true,
        },
        {
          label: "更新时间",
          width: "160",
          prop: "updateTime",
          status: true,
        },
        {
          label: "操作",
          width: "120",
          prop: "",
          status: true,
        },
      ],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        code: [
          {
            required: true,
            message: "请输入条码编码",
            trigger: "blur",
          },
        ],
        barCodeName: [
          {
            required: true,
            message: "请输入条码名称",
            trigger: "blur",
          },
        ],
        barCodeTypeId: [
          {
            required: true,
            message: "请输选择条码类型",
            trigger: "change",
          },
        ],
        stationId: [
          {
            required: true,
            message: "请选择站点",
            trigger: "change",
          },
        ],
        companyId: [
          {
            required: true,
            message: "请选择公司",
            trigger: "change",
          },
        ],
      },
      fromDate: {
        fromid: 1,
        type: 1,
        code: "",
        barCodeName: "",
        companyId: "",
        companyName: "",
        barCodeTypeId: "",
        barCodeTypeName: "",
        stationId: "",
        stationName: "",
        ruleOne: "",
        ruleTwo: "",
        ruleThree: "",
        ruleFour: "",
        ruleFive: "",
        remark: '',
        businessId: '',
      },
      ruleOnerules: {
        // typeId: [
        //   { required: true, message: "请选择编码规则", trigger: "change" },
        // ],
        Name: [
          { required: true, message: "请选择编码规则", trigger: "change" },
        ],
        value: [{ required: true, message: "请选输入值", trigger: "change" }],
      },
      NameList: [
        { label: '日期函数{ddMMyy}', value: '{ddMMyy}' },
        { label: '日期函数{yyMMdd}', value: '{yyMMdd}' },
        { label: '日期函数{yyyy}', value: '{yyyy}' },
        { label: '日期函数{yyyyMM}', value: '{yyyyMM}' },
        { label: '日期函数{yyyyMMdd}', value: '{yyyyMMdd}' },
        { label: '日期函数{ddMMyyyy}', value: '{ddMMyyyy}' },
        { label: '日期函数{yy}', value: '{yy}' },
        { label: '日期函数{yyMM}', value: '{yyMM}' },
      ],
      ruleOne: {
        typeId: null,
        Name: "",
        value: [1, 1, 1],
      },
      ruleTwo: {
        typeId: null,
        Name: "",
        value: [1, 1, 1],
      },
      ruleThree: {
        typeId: null,
        Name: "",
        value: [1, 1, 1],
      },
      ruleFour: {
        typeId: null,
        Name: "",
        value: [1, 1, 1],
      },
      ruleFive: {
        typeId: null,
        Name: "",
        value: [1, 1, 1],
      },
      stationlist: [],
      companylist: [],
      barCodeTypeIdlist: [],
      ruleList: [
        { id: 1, itemName: "固定值" },
        { id: 2, itemName: "函数" },
        { id: 3, itemName: "自增" },
        { id: 5, itemName: "条码类型编码" },
      ],
      businessIdList: [],
      businessIdListA: [//公司级别
        { label: '回弹仪管理', id: 4 },
        { label: '原物料管理', id: 6 },
        { label: '公司标准产品配合比', id: 8 },
        { label: '客户管理', id: 9 },
        { label: '机会管理/销售机会', id: 10 },
        { label: '工程管理', id: 11 },
        { label: '供应商管理', id: 16 },
        { label: '原物料合同', id: 17 },
        { label: '车辆外包合同', id: 18 },
        { label: '设备外包合同', id: 19 },
        { label: '泵管外包合同', id: 20 },
        { label: '外协合同', id: 21 },
        { label: '额外采购下单', id: 22 },
        { label: '异常处理', id: 27 },
        { label: '回弹检验', id: 37 },
        { label: '回弹养护作业', id: 38 },
        { label: '三方检测报告', id: 39 },
        { label: '交工配合比', id: 40 },
        { label: '交工数据管理', id: 41 },
        { label: '原物料结算', id: 42 },
        { label: '混凝土结算', id: 43 },
        { label: '原物料运输结算', id: 44 },
        { label: '混凝土运输结算', id: 45 },
        { label: '泵送作业结算', id: 46 },
        { label: '外协业务结算', id: 47 },
        { label: '协外业务结算', id: 48 },
        { label: '特材库车辆管理', id: 50 },
        { label: '特材成品管理', id: 51 },
        { label: '特材原料管理', id: 52 },
        { label: '特材供应商管理', id: 53 },
        { label: '生产计划', id: 55 },
        { label: '供应商来料', id: 57 },
        { label: '特材质量参数', id: 58 },
        { label: '特材原料检验', id: 59 },
        { label: '特材原料复检', id: 60 },
        { label: '特材成品入库检验', id: 61 },
        { label: '特材成品复检', id: 62 },
        { label: '特材罐 ', id: 65 },
        { label: '周材出库 ', id: 69 },
        { label: '交工资料文档', id: 70 },
      ],
      businessIdListB: [//站点级别
        { label: '车辆管理', id: 1 },
        { label: '泵车管理', id: 2 },
        { label: '计量设备管理', id: 3 },
        { label: '其他设备管理', id: 5 },
        { label: '站点配合比', id: 7 },
        { label: '计划号', id: 23 },
        { label: '采购申请', id: 28 },
        { label: '生产调度', id: 29 },
        { label: '快速检验', id: 30 },
        { label: '原物料复检', id: 32 },
        { label: '原物料抽检', id: 33 },
        { label: '原物料其他检验', id: 34 },
        { label: '出场检验', id: 35 },
        { label: '混凝土其他检验', id: 36 },
        { label: '原物料交货', id: 49 },
        { label: '需求计划', id: 54 },
        { label: '特材运输清单', id: 56 },
        { label: '液位仪', id: 63 },
        { label: '外加剂返料', id: 64 },
        { label: '外加剂返料运输', id: 66 },
        { label: '交工资料', id: 67 },
        { label: '批次检验', id: 31 },
        { label: '抗渗报告 ', id: 68 },
      ],
      multipleType: false,
    };
  },
  async created() {
    this.companylist = await permissionsCompanyList();
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = { ...this.tableParam, barCodeName: "", code: "", businessName: '' };
    this.gettableData();
    getDicType({ code: "barcodeType" }).then((res) => {
      this.barCodeTypeIdlist = res.data.items;
    });
    this.businessIdListFun(1)
  },
  /*
   *copy(data)深拷贝数据,返回拷贝完的数据
   *gettableData获取列表数据
   *load下载
   *SortNum保持序列号
   * UpdateOrDelete禁用，启用，删除
   * submitFromDate保存更新数据
   */
  methods: {
    codingTypesaveCodingTypeFun() {
      let arr = this.arrList.map((e) => {
        return {
          codingTypeId: e.id,  //条码类型id
          codingType: e.codingType,  //条码类型名称
          codingValue: e.codingValue,

        }
      })
      codingTypesaveCodingType(arr).then((res) => {
        if (res.code == 1001) {
          this.$message({
            message: '保存成功',
            type: 'success'
          });
          this.look1Type1 = false
        }
      })
    },
    codingTypegetCodingTypeFun() {
      this.look1Type1 = true
      codingTypegetCodingType().then((res) => {
        if (res.code == 1001) {
          console.log(JSON.parse(JSON.stringify(this.barCodeTypeIdlist)))
          this.barCodeTypeIdlist.map((v) => {
            v.codingType = v.itemName
            let size = res.data.findIndex((e) => e.codingTypeId == v.id)
            if (size === -1) {
              v.codingValue = 0
            } else {
              v.codingValue = res.data[size].codingValue
            }
          })
          this.arrList = this.barCodeTypeIdlist
        }
      })
    },
    businessIdListFun(i, type) {
      if (!type) {
        this.fromDate.businessId = ''
        this.ruleOne.typeId = ''
        this.ruleTwo.typeId = ''
        this.ruleThree.typeId = ''
        this.ruleFour.typeId = ''
        this.ruleFive.typeId = ''
      }
      console.log(i);
      if (i == 1) {
        this.businessIdList = this.businessIdListA
        this.ruleList.splice(4, 1)
      } else {
        this.ruleList.splice(4, 1)
        setTimeout(() => {
          this.$refs.refruleOneD.resetFields();
        }, 50)
        this.businessIdList = this.businessIdListB
        this.$forceUpdate()
        this.ruleList.push({ id: 4, itemName: "站点编码" })
      }
    },
    /**条码规则 回显 */
    show1Fun(e) {
      setTimeout(() => {
        this.businessIdListFun(this.fromDate.type, true)
        this.setstationIdlist()
        console.log(JSON.parse(JSON.stringify(e)))
        this.ruleOne.typeId = Number(e.ruleOne.split('|')[0])
        if (this.ruleOne.typeId != 4 && this.ruleOne.typeId != 5) {
          this.ruleOne.Name = String(e.ruleOne.split('|')[1])
          this.ruleOne.value[0] = String(e.ruleOne.split('|')[1])
          this.ruleOne.value[1] = String(e.ruleOne.split('|')[2])
          this.ruleOne.value[2] = String(e.ruleOne.split('|')[3])
        }
        if (e.ruleTwo) {
          this.ruleTwo.typeId = Number(e.ruleTwo.split('|')[0])
          if (this.ruleTwo.typeId != 4 && this.ruleTwo.typeId != 5) {
            this.ruleTwo.Name = String(e.ruleTwo.split('|')[1])
            this.ruleTwo.value[0] = String(e.ruleTwo.split('|')[1])
            this.ruleTwo.value[1] = String(e.ruleTwo.split('|')[2])
            this.ruleTwo.value[2] = String(e.ruleTwo.split('|')[3])
          }
        } else {
          this.ruleTwo = {
            typeId: null,
            Name: "",
            value: [1, 1, 1],
          }
        }
        if (e.ruleThree) {
          this.ruleThree.typeId = Number(e.ruleThree.split('|')[0])
          if (this.ruleThree.typeId != 4 && this.ruleThree.typeId != 5) {
            this.ruleThree.Name = String(e.ruleThree.split('|')[1])
            this.ruleThree.value[0] = String(e.ruleThree.split('|')[1])
            this.ruleThree.value[1] = String(e.ruleThree.split('|')[2])
            this.ruleThree.value[2] = String(e.ruleThree.split('|')[3])
            console.log(this.ruleThree);
          }
        } else {
          this.ruleThree = {
            typeId: null,
            Name: "",
            value: [1, 1, 1],
          }
        }
        if (e.ruleFour) {
          this.ruleFour.typeId = Number(e.ruleFour.split('|')[0])
          if (this.ruleFour.typeId != 4 && this.ruleFour.typeId != 5) {
            this.ruleFour.Name = String(e.ruleFour.split('|')[1])
            this.ruleFour.value[0] = String(e.ruleFour.split('|')[1])
            this.ruleFour.value[1] = String(e.ruleFour.split('|')[2])
            this.ruleFour.value[2] = String(e.ruleFour.split('|')[3])
          }
        } else {
          this.ruleFour = {
            typeId: null,
            Name: "",
            value: [1, 1, 1],
          }
        }
        if (this.fromDate.type == 2 && e.ruleFive) {
          setTimeout(() => {
            this.ruleFive.typeId = Number(e.ruleFive.split('|')[0])
            if (this.ruleFive.typeId != 4 && this.ruleFive.typeId != 5) {
              this.ruleFive.Name = String(e.ruleFive.split('|')[1])
              this.ruleFive.value[0] = String(e.ruleFive.split('|')[1])
              this.ruleFive.value[1] = String(e.ruleFive.split('|')[2])
              this.ruleFive.value[2] = String(e.ruleFive.split('|')[3])
            }
          }, 100)
        } else {
          this.ruleFive = {
            typeId: null,
            Name: "",
            value: [1, 1, 1],
          }
        }
        this.fromDate.remark = e.remark

      }, 50)
    },
    /*根据公司获取站点*/
    setstationIdlist() {
      getStationByCompanyId({ id: this.fromDate.companyId }).then((res) => {
        this.stationlist = res.data;
        if (res.data.length == 0) {
          this.fromDate.stationId = ''
        }
      });
    },
    codeFun() {
      let json = {
        code: this.fromDate.code,
        id: this.fromDate.id
      }
      qureyCodeIs(json).then((res) => {
        if (res.code == 1001, res.data == false) {
          this.fromDate.code = ''
          this.$message({
            message: '原物料编码已存在',
            type: 'warning'
          });
        }
      })
    },
    init() {
      /*重置数据*/
      this.tableParam.barCodeName = "";
      this.tableParam.businessName = "";
      this.tableParam.code = "";
      this.gettableData();
    },
    setcode(value, name) {
      console.log(name);
      let text = "";
      let _this = this;
      // this.$refs[name].validate((res) => {
      //   if (res) {
      if (value.typeId == 4) {
        let a = _this.stationlist.find(function (obj) {
          return obj.id == _this.fromDate.stationId;
        }).code;
        console.log(_this.stationlist)
        console.log(a)
        text = value.typeId + "|" + a;
      } else if (value.typeId == 5) {
        let a = _this.barCodeTypeIdlist.find(function (obj) {
          return obj.id == _this.fromDate.barCodeTypeId;
        }).itemValue;
        text = value.typeId + "|" + a;
      } else if (value.typeId == 3) {
        text = value.typeId + "|" + value.value.join("|");
      } else if (value.typeId == 2 || value.typeId == 1) {
        text = value.typeId + "|" + value.Name;
      } else {
        text = ''
      }
      //   } else {
      //     text = ''
      //   }
      // });
      return text;
    },
    submit() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          if (
            _this.ruleOne.typeId == 3 ||
            _this.ruleTwo.typeId == 3 ||
            _this.ruleThree.typeId == 3 ||
            _this.ruleFour.typeId == 3 ||
            _this.fromDate.type == 2 && _this.ruleFive.typeId == 3
          ) {
            _this.fromDate.ruleOne = _this.setcode(_this.ruleOne, "refruleOne");
            if (!_this.fromDate.ruleOne) {
              return;
            }
            _this.fromDate.ruleTwo = _this.setcode(
              _this.ruleTwo,
              "refruleOneA"
            );
            // if (!_this.fromDate.ruleTwo) {
            //   return;
            // }
            _this.fromDate.ruleThree = _this.setcode(
              _this.ruleThree,
              "refruleOneB"
            );
            // if (!_this.fromDate.ruleThree) {
            //   return;
            // }
            _this.fromDate.ruleFour = _this.setcode(
              _this.ruleFour,
              "refruleOneC"
            );
            // if (!_this.fromDate.ruleFour) {
            //   return;
            // }
            if (_this.fromDate.type == 2) {
              _this.fromDate.ruleFive = _this.setcode(
                _this.ruleFive,
                "refruleOneD"
              );
              // if (!_this.fromDate.ruleFive) {
              //   return;
              // }
            }
            if (_this.fromDate.type == 2) {
              _this.fromDate.stationName = _this.stationlist.find(function (obj) {
                return obj.id == _this.fromDate.stationId;
              }).stationName;
            }
            _this.fromDate.companyName = _this.companylist.find(function (
              obj
            ) {
              return obj.id == _this.fromDate.companyId;
            }).name;
            _this.fromDate.barCodeTypeName = _this.barCodeTypeIdlist.find(
              function (obj) {
                return obj.id == _this.fromDate.barCodeTypeId;
              }
            ).itemName;
            if (this.multipleType) {
              let arr = []
              this.fromDate.businessId.forEach((v) => {
                let item = this.businessIdList.find((res) => res.id == v)
                console.log(item.id);
                arr.push({
                  ...this.fromDate,
                  businessId: item.id,
                  businessName: item.label
                })
              })
              this.loading = true;
              _this.submitFromDate(arr);
            } else {
              this.fromDate.businessName = this.businessIdList.find((res) => res.id == this.fromDate.businessId).label;
              this.loading = true;
              _this.submitFromDate([_this.fromDate]);
            }
          } else {
            this.$message({
              message: "警告哦，至少有一个自增规则",
              type: "warning",
            });
          }
        } else {
          return false;
        }
      });
    },
    chongZhi() {
      this.addDialog = true
      setTimeout(() => {
        this.$data.fromDate = this.$options.data().fromDate
        this.$refs.reffromDate.resetFields();
        this.$data.ruleOne = this.$options.data().ruleOne
        this.$data.ruleTwo = this.$options.data().ruleTwo
        this.$data.ruleThree = this.$options.data().ruleThree
        this.$data.ruleFour = this.$options.data().ruleFour
        this.$data.ruleFive = this.$options.data().ruleFive
        this.$refs.refruleOne.resetFields();
        this.$refs.refruleOneA.resetFields();
        this.$refs.refruleOneB.resetFields();
        this.$refs.refruleOneC.resetFields();
        this.businessIdListFun(1)
        this.$forceUpdate()
      }, 100)
    }
  },
};
</script>

<style lang="scss" scoped>
.el-input,
.el-select {
  width: 320px;
}
</style>
